package org.alex.samples.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.alex.samples.model.ExamTestType;
import org.alex.samples.model.ExamTestVO;

public class TestUtils {

	public static boolean checkSubjectScoreAndCount(Integer totalTestCount, Integer totalTestScore,
			Map<Integer, Integer> testTypeScoreMap) {
		return true;
	}

	//通过分数得到试题
	public static Map<Integer, Integer> getTestCountByScore(Integer totalTestCount , Integer totalTestScore, Map<Integer, Integer> testTypeScoreMap, List<ExamTestType> examTestType) {
		for(int i=1;i<totalTestCount;i++){
			for(int j=totalTestCount-i;j>0;j--){
			int x=testTypeScoreMap.get(examTestType.get(0).getId()); //获取x的分数
			int y=testTypeScoreMap.get(examTestType.get(1).getId());			
			if(i+j==totalTestCount && i*x + j*y == totalTestScore){
				Map<Integer,Integer> map=new HashMap<Integer,Integer>();
				map.put(examTestType.get(0).getId(), i);
				map.put(examTestType.get(1).getId(), j);
				return map;
			}
		  }
		}
		return null;
	}

	//随机得到试题
	public static List<Integer> getRandomTestIdList(List<ExamTestVO> testList, Integer count) {
		List<Integer> randomTestList = new ArrayList<Integer>();
		int size = testList.size();
		Collections.shuffle(testList);
		if(size > count){
			for(int i = 0; i < count; i++){
				randomTestList.add(testList.get(i).getId());
			}
			return randomTestList;
		}else if(size == count){
			for(ExamTestVO vo : testList){
				randomTestList.add(vo.getId());
			}
			return randomTestList;
		}else{
			return null;
		}
	}
	
}
